package com.kaifamiao.contraller;

import com.kaifamiao.model.JianyiModel;
import com.kaifamiao.model.UserModel;
import com.kaifamiao.service.JianyiModelService;
import com.kaifamiao.service.UserService;
import com.kaifamiao.util.ResponseUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class JianyiContraller {

    @Autowired
    private JianyiModelService service;

    @RequestMapping("/shanchujianYi")
    @CrossOrigin("*")
    public ResponseUtil shanchujianYi(@RequestParam(value = "id",required = false) Long id,
                                      @RequestParam(value = "uid",required = false) Long uid){
        int i= service.deleteByPrimaryKey(id,uid);
//        System.out.println(i);
        if(i > 0){
            return ResponseUtil.ok("删除成功");
        }else {
            return ResponseUtil.ok("删除失败");
        }
    }

    @RequestMapping("/zengjiajianYi")
    @CrossOrigin("*")
    public ResponseUtil zengjiajianYi(@RequestParam(value = "uid",required = false) int uid,
                                      @RequestParam(value = "neirong",required = false) String neirong) {
        JianyiModel jianyiModel = new JianyiModel();
        jianyiModel.setNeirong(neirong);
        jianyiModel.setUid(uid);
        int i = service.insertSelective(jianyiModel);

        if (i > 0) {
            return ResponseUtil.ok("添加成功");
        } else {
            return ResponseUtil.ok("添加失败");
        }

    }

    @RequestMapping("/chakanjiajianYi")
    @CrossOrigin("*")
    public ResponseUtil zengjiajianYi() {

        List<JianyiModel> list = service.selectAll();

        if (list.size() >= 0) {
            return ResponseUtil.ok("查看成功",list);
        } else {
            return ResponseUtil.ok("查看失败");
        }

    }

}
